/*
 * @(#)ClassInspector.java	1.0 Apr 26, 2008
 *
 *	The MIT License
 *
 *	Copyright (c) 2008 Malachi de AElfweald <malachid@gmail.com>
 *
 *	Permission is hereby granted, free of charge, to any person obtaining a copy
 *	of this software and associated documentation files (the "Software"), to deal
 *	in the Software without restriction, including without limitation the rights
 *	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *	copies of the Software, and to permit persons to whom the Software is
 *	furnished to do so, subject to the following conditions:
 *
 *	The above copyright notice and this permission notice shall be included in
 *	all copies or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *	THE SOFTWARE.
 */
package org.eoti.reflect;

import java.io.PrintStream;
import java.io.PrintWriter;

public class ClassInspector
{
	protected Class toInspect;

	public ClassInspector(String toInspect)
		throws ClassNotFoundException
	{
		this(Class.forName(toInspect));
	}

	public ClassInspector(Object toInspect)
	{
		this(toInspect.getClass());
	}

	public ClassInspector(Class toInspect)
	{
		this.toInspect = toInspect;
	}

	public void display()
	{
		display(System.out);
	}

	public void display(PrintStream out)
	{
		display(new PrintWriter(out));
	}

	public void display(PrintWriter out)
	{
		out.format("ClassInspector.display of '%s'\n", toInspect);
		out.format("----------------------------------------------\n");
		display(out, "CanonicalName", toInspect.getCanonicalName());
		display(out, "Name", toInspect.getName());
		display(out, "Package", toInspect.getPackage());
		display(out, "SimpleName", toInspect.getSimpleName());
		display(out, "ClassLoader", toInspect.getClassLoader());
		display(out, "ProtectionDomain", toInspect.getProtectionDomain());
		display(out, "ComponentType", toInspect.getComponentType());
		display(out, "DeclaringClass", toInspect.getDeclaringClass());
		display(out, "EnclosingClass", toInspect.getEnclosingClass());
		display(out, "SuperClass", toInspect.getSuperclass());
        display(out, "EnclosingMethod", toInspect.getEnclosingMethod());
		display(out, "Classes", toInspect.getClasses());
		display(out, "DeclaredClasses", toInspect.getDeclaredClasses());
		display(out, "Interfaces", toInspect.getInterfaces());
		display(out, "GenericInterfaces", toInspect.getGenericInterfaces());
        display(out, "Methods", toInspect.getMethods());
		display(out, "DeclaredMethods", toInspect.getDeclaredMethods());
		display(out, "Fields", toInspect.getFields());
		display(out, "DeclaredFields", toInspect.getDeclaredFields());
		out.println();
	}

	protected void display(PrintWriter out, String name, Object[] value)
	{
		out.format("%-20s: \n", name);
		for(Object obj : value)
			out.format("%22s%s\n","",obj);
	}

	protected void display(PrintWriter out, String name, Object value)
	{
		out.format("%-20s: %s\n", name, value);
	}
}
